import math


class Solution(object):
    def minEatingSpeed(self, piles, h):
        """
        :type piles: List[int]
        :type h: int
        :rtype: int
        """
        if h < len(piles):
            return 0
        all = sum(piles)
        speed = int(all / h)
        if speed < 1:
            return 1
        while True:
            hCnt = 0
            for p in piles:
                if p % speed == 0:
                    hCnt += p / speed
                else:
                    hCnt += int(p/speed) + 1
                # hCnt += math.ceil(p / speed)
                if hCnt > h:
                    break
            if hCnt <= h:
                return speed
            speed += 1


s = Solution()

res = s.minEatingSpeed([3,6,7,11], 8)
print(res)
res = s.minEatingSpeed([30,11,23,4,20], 6)
print(res)
res = s.minEatingSpeed([30,11,23,4,20], 10)
print(res)